import React, { Component } from 'react';
import { Form, Input, Button, Select } from 'antd'
import { changeAdminL } from '@/service/people';
import { history } from 'umi'

const formItemLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};
const onFinish = (values: any) => {
  const { adminname, password, role } = values
  changeAdminL({ adminname, password, role, checkedKeys: [] }).then((res) => {
    history.push('/people/admin')
  })
};

const { Option } = Select;
class changeAdmin extends Component {
  constructor(props: any) {
    super(props)
  }
  // componentDidMount(){
  //     console.log(this.props.location.query.adminname);
  // }

  render() {

    return (
      <>
        <div>
          <Form
            name="validate_other"
            {...formItemLayout}
            onFinish={onFinish}
            initialValues={{
              'adminname': this.props.location.query.adminname,
              'password': '',
              'role': ''
            }}
          >
            <Form.Item label="Plain Text">
              <span className="ant-form-text">修改管理员信息</span>
            </Form.Item>
            <Form.Item
              name="adminname"
              label="adminname"
              required
            >
              <Input size="large" placeholder="请输入管理员名称" />
            </Form.Item>
            <Form.Item
              name="password"
              label="password"
              required
            >
              <Input size="large" placeholder="请输入密码" />
            </Form.Item>
            <Form.Item
              name="role"
              label="role"
              required
            >
              <Select defaultValue="管理员" style={{ width: 120 }} allowClear>
                <Option value="1">管理员</Option>
                <Option value="2">超级管理员</Option>
              </Select>
            </Form.Item>
            <Form.Item wrapperCol={{ span: 12, offset: 6 }}>
              <Button type="primary" htmlType="submit">
                Submit
            </Button>
            </Form.Item>
          </Form>
        </div>
      </>
    );
  }
}

export default changeAdmin;